package com.williambucciero.mobilemuseum;

import java.io.DataOutputStream;
import java.util.Calendar;

import android.content.Context;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;

import com.williambucciero.mobilemuseum.R;

public class DebugReporter {
	Context ctxt;
	
	
	public DebugReporter(Context ctxt){
		this.ctxt = ctxt;
	}
	
	public void writeToFile(String toWrite){
		PowerManager pm = (PowerManager) ctxt.getSystemService(Context.POWER_SERVICE);
		WakeLock myWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, ctxt.getResources().getString(R.string.app_name));
		myWakeLock.acquire();
		try{
			DataOutputStream out = new DataOutputStream(ctxt.openFileOutput("debug.txt", Context.MODE_APPEND));
			Calendar c = Calendar.getInstance();
			out.writeUTF(c.get(Calendar.YEAR) + " " + c.get(Calendar.DAY_OF_YEAR) + " " + c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND) + "   " + toWrite + '\n');
			out.close();
		} catch (Exception e) {
		}
		myWakeLock.release();
	}
}
